home *** CD-ROM | disk | FTP | other *** search
- //Licensed under GNU General Public License, version 3.0
- //Copyright Damien Brunet
- //I'm working on a Google Chrome port (actually several ports... aFCA has too many features)
-
- var aFCA =
- {
- getSelectedText: function ()
- {
- var selection = document.commandDispatcher.focusedWindow.getSelection();
-
- if (selection)
- {
- var text = aFCA.trim(selection.toString());
- }
- else
- {
- var text = "";
- }
-
- return text;
- },
-
-
- getSelectedTextWithin: function ()
- {
- var popupNode = document.popupNode;
-
-
- if (popupNode && ((popupNode.localName.toLowerCase() == "input" && popupNode.type == "text") || popupNode.localName.toLowerCase() == "textarea"))
- {
- var text = aFCA.trim(popupNode.value.substring(popupNode.selectionStart, popupNode.selectionEnd));
- }
- else
- {
- var text = "";
- }
-
- return text;
- },
-
-
- trim: function (text)
- {
- return text.replace(/^\s+/, "").replace(/\s+$/, "").replace(/\s+/g, " ");
- },
-
-
- getUrl: function (item, from)
- {
- var text = encodeURIComponent(aFCA.lastSelection);
-
- switch (item)
- {
- case "googleTranslate":
- {
- if (from == "input")
- {
- var srcLang = aFCA.p.quickW.srcLang;
- var destLang = aFCA.p.quickW.destLang;
- }
- else
- {
- var srcLang = aFCA.p.quick.srcLang;
- var destLang = aFCA.p.quick.destLang;
- }
-
- return "http://translate.google.com/#" + srcLang + "|" + destLang + "|" + text;
- }
- case "googleDictionary":
- {
- if (aFCA.p.googleDictionary.mono && aFCA.p.googleDictionary.lang == "auto|auto")
- {
- aFCA.detectLanguage(text, function (lang)
- {
- var lang = lang + "|" + lang;
-
- if (!aFCA.isInMonolingualDictionary(lang))
- {
- lang = "en|en";
- }
-
- var url = "http://www.google.com/dictionary?langpair=" + lang + "&q=" + text;
-
- aFCA.openItem(url);
- }
- )
-
- return;
- }
- else if (aFCA.p.googleDictionary.bi && aFCA.p.googleDictionary.langpair == "auto|en")
- {
- aFCA.detectLanguage(text, function (lang)
- {
- var langpair = lang + "|" + "en";
-
- if (!aFCA.isInBilingualDictionary(langpair))
- {
- langpair = "en|en";
- }
-
- var url = "http://www.google.com/dictionary?langpair=" + langpair + "&q=" + text;
-
- aFCA.openItem(url);
- }
- )
-
- return;
- }
- else if (aFCA.p.googleDictionary.bi)
- {
- return "http://www.google.com/dictionary?langpair=" + aFCA.p.googleDictionary.langpair + "&q=" + text;
- }
- else
- {
- return "http://www.google.com/dictionary?langpair=" + aFCA.p.googleDictionary.lang + "&q=" + text;
- }
- }
- case "customItem1":
- {
- return aFCA.p.customItem1.url.replace(/%s/g, text);
- }
- case "customItem2":
- {
- return aFCA.p.customItem2.url.replace(/%s/g, text);
- }
- case "customItem3":
- {
- return aFCA.p.customItem3.url.replace(/%s/g, text);
- }
- case "newChildTab":
- {
- return gContextMenu.linkURL;
- }
- case "translateThisPage":
- {
- return "http://translate.google.com/translate?sl=auto&tl=" + aFCA.p.translateThisPage.destLang + "&u=" + aFCA.getCurrentUrl();
- }
- default:
- {
- return item;
- }
- }
- },
-
-
- isInMonolingualDictionary: function (lang)
- {
- var list = ["zh-CN|zh-CN", "zh-TW|zh-TW", "cs|cs", "nl|nl", "en|en", "fr|fr", "de|de", "it|it", "ko|ko", "pt|pt", "ru|ru", "es|es"];
-
- for (var i = 0; i < list.length; i++)
- {
- if (list[i] == lang)
- {
- return true;
- }
- }
-
- return false;
- },
-
-
- isInBilingualDictionary: function (langpair)
- {
- var list = ["ar|en", "bn|en", "bg|en", "zh-CN|en", "zh-TW|en", "hr|en", "cs|en", "fi|en", "fr|en", "de|en", "el|en", "gu|en", "iw|en", "hi|en", "it|en", "kn|en", "ko|en", "ml|en", "mr|en", "pt|en", "ru|en", "sr|en", "es|en", "ta|en", "te|en", "th|en"];
-
- for (var i = 0; i < list.length; i++)
- {
- if (list[i] == langpair)
- {
- return true;
- }
- }
-
- return false;
- },
-
-
- openItem: function (item, from)
- {
- var url = aFCA.getUrl(item, from);
-
- if (!url)
- {
- return;
- }
-
- var parentTab = gBrowser.selectedTab;
- var childTab = gBrowser.addTab(url);
-
- if (aFCA.p.stuff.here && from != "input")
- {
- aFCA.hideBubble();
-
- if (aFCA.p.stuff.unselect)
- {
- goDoCommand('cmd_selectNone');
- }
-
- if (item == "customItem1" || item == "customItem2" || item == "customItem3" || item == "googleDictionary" || item == "googleTranslate" || item.match("q="))
- {
- aFCA.updateHereDisplay(aFCA.lastSelectionEvent);
- }
- else if (item == "newChildTab")
- {
- aFCA.updateHereDisplay(aFCA.lastRightClick);
- }
- }
-
- gBrowser.selectedTab = childTab;
-
- if (aFCA.p.stuff.bool)
- {
- aFCA.tagTabs(childTab, parentTab);
- }
- },
-
-
- tagTabs: function (childTab, parentTab)
- {
- var parentTabID = aFCA.ss.getTabValue(parentTab, "ID");
-
- if (!parentTabID)
- {
- var parentTabID = Math.floor(Math.random()*10000);
- aFCA.ss.setTabValue(parentTab, "ID", parentTabID);
- }
-
- aFCA.ss.setTabValue(childTab, "parentTabID", parentTabID);
- },
-
-
- init: function ()
- {
- aFCA.translated = true;
-
- aFCA.ss = Components.classes["@mozilla.org/browser/sessionstore;1"]
- .getService(Components.interfaces.nsISessionStore);
-
- aFCA.pf = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService)
-
- aFCA.prefsAfca = aFCA.pf.getBranch("extensions.aFCA.");
- aFCA.prefsGeneral = aFCA.pf.getBranch("general.");
-
- aFCA.getPrefs();
-
- aFCA.prefsAfca.QueryInterface(Components.interfaces.nsIPrefBranch2);
- aFCA.prefsAfca.addObserver("", this, false);
-
- if (aFCA.p.stuff.middleClick)
- {
- aFCA.prefsGeneral.setBoolPref("autoScroll", false);
- }
-
- if (aFCA.p.autoConfig)
- {
- aFCA.autoConfig();
- }
-
- function onTabSelect (e)
- {
- aFCA.hideSkin();
- }
- gBrowser.tabContainer.addEventListener("TabSelect", function (e) {onTabSelect(e);}, false);
-
- function onPageLoad (e)
- {
- var doc = e.originalTarget;
- var indexTab = gBrowser.getBrowserIndexForDocument(doc);
-
- if (indexTab == -1 || !doc.body)
- {
- return;
- }
-
- if (aFCA.ss.getTabValue(gBrowser.mTabs[indexTab], "parentTabID") && aFCA.p.stuff.middleClick)
- {
- aFCA.initSkin(doc);
- }
-
- if (aFCA.p.quick.bubble)
- {
- aFCA.initBubble(doc);
- }
-
- if (aFCA.p.stuff.here)
- {
- aFCA.initHere(doc);
- }
- }
- document.addEventListener("DOMContentLoaded", function (e) {onPageLoad(e);}, false);
-
- aFCA.getMenuItems();
-
- function onPopupShowing (e)
- {
- if (e.target.id != "contentAreaContextMenu")
- {
- return;
- }
-
- aFCA.drawMenu();
- }
- document.addEventListener("popupshowing", function (e) {onPopupShowing(e);}, false);
- },
-
-
- autoConfig: function ()
- {
- var locale = aFCA.p.locale;
- var lang = locale.replace(/-.+/, "");
-
- if (lang == "he")
- {
- lang = "iw";
- }
-
- if (aFCA.isSupportedByGoogleApi(locale))
- {
- aFCA.prefsAfca.setCharPref("quick.destLang", locale);
- aFCA.prefsAfca.setCharPref("quickW.destLang", locale);
- aFCA.prefsAfca.setCharPref("translateThisPage.destLang", locale);
- }
- else if (aFCA.isSupportedByGoogleApi(lang))
- {
- aFCA.prefsAfca.setCharPref("quick.destLang", lang);
- aFCA.prefsAfca.setCharPref("quickW.destLang", lang);
- aFCA.prefsAfca.setCharPref("translateThisPage.destLang", lang);
- }
-
- if (aFCA.isInBilingualDictionary(locale + "|en"))
- {
- aFCA.prefsAfca.setCharPref("googleDictionary.langpair", "en|" + locale);
- }
- else if (aFCA.isInBilingualDictionary(lang + "|en"))
- {
- aFCA.prefsAfca.setCharPref("googleDictionary.langpair", "en|" + lang);
- }
-
- aFCA.prefsAfca.setBoolPref("autoConfig", false);
- },
-
-
- isSupportedByGoogleApi: function (lang)
- {
- var list = ["af", "sq", "ar", "be", "bg", "ca", "zh-CN", "zh-TW", "hr", "cs", "da", "nl", "en", "et", "tl", "fi", "fr", "gl", "de", "el", "iw", "hi", "hu", "is", "id", "ga", "it", "ja", "ko", "lv", "lt", "mk", "ms", "mt", "no", "fa", "pl", "pt", "ro", "ru", "sr", "sk", "sl", "es", "sw", "sv", "th", "tr", "uk", "vi", "cy", "yi"];
-
- for (var i = 0; i < list.length; i++)
- {
- if (list[i] == lang)
- {
- return true;
- }
- }
-
- return false;
- },
-
-
- closeAndGo: function (from)
- {
- var childTab = gBrowser.selectedTab;
- var parentTabID = aFCA.ss.getTabValue(childTab, "parentTabID");
- var tabCount = gBrowser.mPanelContainer.childNodes.length;
-
- for (var tab, found = false, i = 0; i < tabCount && !found; i++)
- {
- tab = gBrowser.mTabs[i];
-
- if (aFCA.ss.getTabValue(tab, "ID") == parentTabID)
- {
- gBrowser.selectedTab = tab;
- found = true;
- }
- }
-
- if (aFCA.lastMouseMove && content.document.getElementById("skin") && from == "click")
- {
- aFCA.updateSkinDisplay(aFCA.lastMouseMove);
- }
-
- if (!found)
- {
- gBrowser.removeTab(childTab);
- }
- else
- {
- setTimeout(function () {gBrowser.removeTab(childTab);}, 100); //In order to avoid the "flicker"
- }
- },
-
-
- injectStretch: function (doc)
- {
- aFCA.injectStyle(doc, "html {width: 100%; height: 100%;}", "stretch");
- },
-
-
- restoreChildTab: function ()
- {
- var list = JSON.parse(aFCA.ss.getClosedTabData(window));
-
- var currentTab = gBrowser.selectedTab;
- var currentTabID = aFCA.ss.getTabValue(currentTab, "ID");
-
- for (var i = 0; i < list.length; i++)
- {
- if (list[i].state.extData && list[i].state.extData.parentTabID && list[i].state.extData.parentTabID == currentTabID)
- {
- aFCA.ss.undoCloseTab(window, i);
- break;
- }
- }
- },
-
- //gTranslate
- replaceSelection: function ()
- {
- var popupNode = document.popupNode;
- var iStart = popupNode.selectionStart;
- var iEnd = popupNode.selectionEnd;
- var trans = aFCA.processText(aFCA.lastTranslation);
- popupNode.value = popupNode.value.substring(0, iStart) + trans + popupNode.value.substring(iEnd, popupNode.value.length);
- popupNode.setSelectionRange(iStart, iStart + trans.length);
- },
-
-
- getCurrentUrl: function ()
- {
- return gBrowser.selectedBrowser.currentURI.spec;
- },
-
-
- getMenuItems: function ()
- {
- aFCA.menu_quick = document.getElementById("aFCA-menu-quick");
- aFCA.item2_quick = document.getElementById("aFCA-item2-quick");
- aFCA.translateFrom = document.getElementById("aFCA-translateFrom");
- aFCA.translateTo = document.getElementById("aFCA-translateTo");
- aFCA.item1_quick = document.getElementById("aFCA-item1-quick");
- aFCA.sep_quick = document.getElementById("aFCA-sep-quick");
- aFCA.item_googleDictionary = document.getElementById("aFCA-googleDictionary");
- aFCA.item_customItem1 = document.getElementById("aFCA-customItem1");
- aFCA.item_customItem2 = document.getElementById("aFCA-customItem2");
- aFCA.item_customItem3 = document.getElementById("aFCA-customItem3");
- aFCA.sep_searchItems = document.getElementById("aFCA-sep-searchItems");
- aFCA.item_newChildTab = document.getElementById("aFCA-newChildTab");
- aFCA.sep_newChildTab = document.getElementById("aFCA-sep-newChildTab");
- aFCA.item_restoreChildTab = document.getElementById("aFCA-restoreChildTab");
- aFCA.sep_restoreChildTab = document.getElementById("aFCA-sep-restoreChildTab");
- aFCA.item_translateThisPage = document.getElementById("aFCA-translateThisPage");
- aFCA.sep_translateThisPage = document.getElementById("aFCA-sep-translateThisPage");
- aFCA.item_closeThisChildTab = document.getElementById("aFCA-closeThisChildTab");
- aFCA.sep_closeThisChildTab = document.getElementById("aFCA-sep-closeThisChildTab");
- aFCA.item_blacklist = document.getElementById("aFCA-blacklist");
- aFCA.sep_blacklist = document.getElementById("aFCA-sep-blacklist");
-
- aFCA.stringsBundle = document.getElementById("aFCA-stringsBundle");
-
- aFCA.item_openlink = document.getElementById("context-openlink");
- aFCA.item_bookmarklink = document.getElementById("context-bookmarklink");
- aFCA.item_sendlink = document.getElementById("context-sendlink");
- aFCA.item_sendimage = document.getElementById("context-sendimage");
- aFCA.item_setDesktopBackground = document.getElementById("context-setDesktopBackground");
- aFCA.item_blockimage = document.getElementById("context-blockimage");
- aFCA.item_sendvideo = document.getElementById("context-sendvideo");
- aFCA.item_sendaudio = document.getElementById("context-sendaudio");
- aFCA.item_back = document.getElementById("context-back");
- aFCA.item_forward = document.getElementById("context-forward");
- aFCA.item_reload = document.getElementById("context-reload");
- aFCA.item_stop = document.getElementById("context-stop");
- aFCA.sep_stop = document.getElementById("context-sep-stop");
- aFCA.item_bookmarkpage = document.getElementById("context-bookmarkpage");
- aFCA.item_savepage = document.getElementById("context-savepage");
- aFCA.item_sendpage = document.getElementById("context-sendpage");
- aFCA.sep_viewbgimage = document.getElementById("context-sep-viewbgimage");
- aFCA.item_viewbgimage = document.getElementById("context-viewbgimage");
- aFCA.item_undo = document.getElementById("context-undo");
- aFCA.sep_undo = document.getElementById("context-sep-undo");
- aFCA.item_cut = document.getElementById("context-cut");
- aFCA.item_copy = document.getElementById("context-copy");
- aFCA.item_paste = document.getElementById("context-paste");
- aFCA.item_delete = document.getElementById("context-delete");
- aFCA.sep_paste = document.getElementById("context-sep-paste");
- aFCA.item_selectall = document.getElementById("context-selectall");
- aFCA.sep_selectall = document.getElementById("context-sep-selectall");
- aFCA.item_keywordfield = document.getElementById("context-keywordfield");
- aFCA.item_searchselect = document.getElementById("context-searchselect");
- aFCA.sep_frame = document.getElementById("frame-sep");
- aFCA.menu_frame = document.getElementById("frame");
- aFCA.item_viewpartialsourceSelection = document.getElementById("context-viewpartialsource-selection");
- aFCA.item_viewpartialsourceMathml = document.getElementById("context-viewpartialsource-mathml");
- aFCA.sep_viewsource = document.getElementById("context-sep-viewsource");
- aFCA.item_viewsource = document.getElementById("context-viewsource");
- aFCA.item_viewinfo = document.getElementById("context-viewinfo");
- aFCA.sep_spell = document.getElementById("spell-separator");
- aFCA.item_spellCheck = document.getElementById("spell-check-enabled");
-
- aFCA.item_saveimage = document.getElementById("context-saveimage");
-
- //To-Remove after 3.6
- aFCA.sep_properties = document.getElementById("context-sep-properties");
- aFCA.item_metadata = document.getElementById("context-metadata");
- },
-
-
- drawMenu: function ()
- {
- var text = aFCA.getSelectedText();
- var textWithin = aFCA.getSelectedTextWithin();
- var doc = content.document;
-
- aFCA.menu_quick.hidden = true;
- aFCA.item1_quick.hidden = true;
- aFCA.sep_quick.hidden = true;
- aFCA.item_googleDictionary.hidden = true;
- aFCA.item_customItem1.hidden = true;
- aFCA.item_customItem2.hidden = true;
- aFCA.item_customItem3.hidden = true;
- aFCA.sep_searchItems.hidden = true;
- aFCA.item_newChildTab.hidden = true;
- aFCA.sep_newChildTab.hidden = true;
- aFCA.item_restoreChildTab.hidden = true;
- aFCA.sep_restoreChildTab.hidden = true;
- aFCA.item_translateThisPage.hidden = true;
- aFCA.sep_translateThisPage.hidden = true;
- aFCA.item_closeThisChildTab.hidden = true;
- aFCA.sep_closeThisChildTab.hidden = true;
- aFCA.item_blacklist.hidden = true;
- aFCA.sep_blacklist.hidden = true;
-
- if (aFCA.p.pruning.openlink)
- {
- aFCA.item_openlink.hidden = true;
- }
- if (aFCA.p.pruning.bookmarklink)
- {
- aFCA.item_bookmarklink.hidden = true;
- }
- if (aFCA.p.pruning.sendlink)
- {
- aFCA.item_sendlink.hidden = true;
- }
- if (aFCA.p.pruning.sendimage)
- {
- aFCA.item_sendimage.hidden = true;
- }
- if (aFCA.p.pruning.setDesktopBackground)
- {
- aFCA.item_setDesktopBackground.hidden = true;
- }
- if (aFCA.p.pruning.blockimage)
- {
- aFCA.item_blockimage.hidden = true;
- }
- if (aFCA.p.pruning.sendvideo)
- {
- aFCA.item_sendvideo.hidden = true;
- }
- if (aFCA.p.pruning.sendaudio)
- {
- aFCA.item_sendaudio.hidden = true;
- }
- if (aFCA.p.pruning.back)
- {
- aFCA.item_back.hidden = true;
- }
- if (aFCA.p.pruning.forward)
- {
- aFCA.item_forward.hidden = true;
- }
- if (aFCA.p.pruning.reload)
- {
- aFCA.item_reload.hidden = true;
- }
- if (aFCA.p.pruning.stop)
- {
- aFCA.item_stop.hidden = true;
- }
- if (aFCA.p.pruning.stop && aFCA.p.pruning.reload && aFCA.p.pruning.forward && aFCA.p.pruning.back)
- {
- aFCA.sep_stop.hidden = true;
- }
- if (aFCA.p.pruning.bookmarkpage)
- {
- aFCA.item_bookmarkpage.hidden = true;
- }
- if (aFCA.p.pruning.savepage)
- {
- aFCA.item_savepage.hidden = true;
- }
- if (aFCA.p.pruning.sendpage)
- {
- aFCA.item_sendpage.hidden = true;
- }
- if (aFCA.p.pruning.viewbgimage)
- {
- aFCA.item_viewbgimage.hidden = true;
- aFCA.sep_viewbgimage.hidden = true;
- }
- if (aFCA.p.pruning.undo)
- {
- aFCA.item_undo.hidden = true;
- aFCA.sep_undo.hidden = true;
- }
- if (aFCA.p.pruning.cut)
- {
- aFCA.item_cut.hidden = true;
- }
- if (aFCA.p.pruning.copy)
- {
- aFCA.item_copy.hidden = true;
- }
- if (aFCA.p.pruning.paste)
- {
- aFCA.item_paste.hidden = true;
- }
- if (aFCA.p.pruning.del)
- {
- aFCA.item_delete.hidden = true;
- }
- if (aFCA.p.pruning.selectall)
- {
- aFCA.item_selectall.hidden = true;
- aFCA.sep_selectall.hidden = true;
- }
- if ((aFCA.item_cut.hidden && aFCA.item_copy.hidden && aFCA.item_paste.hidden && aFCA.item_delete.hidden) || (aFCA.item_keywordfield.hidden && aFCA.item_selectall.hidden))
- {
- aFCA.sep_paste.hidden = true;
- }
- if (aFCA.p.pruning.searchselect)
- {
- aFCA.item_searchselect.hidden = true;
- }
- if (aFCA.p.pruning.frame)
- {
- aFCA.menu_frame.hidden = true;
- aFCA.sep_frame.hidden = true;
- }
- if (aFCA.p.pruning.viewpartialsourceSelection)
- {
- aFCA.item_viewpartialsourceSelection.hidden = true;
- }
- if (aFCA.p.pruning.viewsource)
- {
- aFCA.item_viewsource.hidden = true;
- }
- if (aFCA.sep_viewsource && ((aFCA.item_viewsource.hidden && aFCA.item_viewinfo.hidden) || aFCA.item_savepage.hidden))
- {
- aFCA.sep_viewsource.hidden = true;
- }
- if (aFCA.p.pruning.spellCheck)
- {
- aFCA.item_spellCheck.hidden = true;
- aFCA.sep_spell.hidden = true;
- }
-
- //To-Remove
- if (aFCA.item_metadata)
- {
- aFCA.item_metadata.hidden = true;
- }
- if (aFCA.sep_properties && (aFCA.item_viewpartialsourceSelection.hidden && aFCA.item_viewsource.hidden && aFCA.item_viewpartialsourceMathml.hidden && aFCA.item_viewinfo.hidden || aFCA.item_savepage.hidden))
- {
- aFCA.sep_properties.hidden = true;
- }
-
- if (textWithin && aFCA.p.quick.bool)
- {
- aFCA.lastSelection = textWithin;
-
- if (textWithin.length > 20)
- {
- textWithin = textWithin.substr(0, 20) + "…";
- }
-
- var label_quickMenu = aFCA.stringsBundle.getFormattedString("quickMenu.label", [textWithin]);
- var accesskey_quickMenu = aFCA.stringsBundle.getString("quickMenu.accesskey");
-
- aFCA.menu_quick.label = label_quickMenu;
- aFCA.menu_quick.setAttribute("accesskey", accesskey_quickMenu);
- aFCA.menu_quick.hidden = false;
- aFCA.sep_quick.hidden = false;
-
- if (aFCA.item_undo.hidden && aFCA.item_cut.hidden && aFCA.item_copy.hidden && aFCA.item_paste.hidden && aFCA.item_delete.hidden && aFCA.item_selectall && aFCA.item_spellCheck.hidden && aFCA.item_keywordfield.hidden)
- {
- aFCA.sep_quick.hidden = true;
- }
-
- var srcLang = aFCA.codeToLanguage(aFCA.p.quickW.srcLang);
- var destLang = aFCA.codeToLanguage(aFCA.p.quickW.destLang);
-
- var label_googleTranslate = aFCA.stringsBundle.getString("googleTranslate.label");
- var label_translateFrom = aFCA.stringsBundle.getFormattedString("translateFrom.label", [srcLang]);
- var label_translateTo = aFCA.stringsBundle.getFormattedString("translateTo.label", [destLang]);
-
- aFCA.item2_quick.label = label_googleTranslate;
- aFCA.translateFrom.label = label_translateFrom;
- aFCA.translateTo.label = label_translateTo;
- }
- else if (text && !gContextMenu.onLink && (!gContextMenu.isOnImage && aFCA.item_saveimage.hidden))
- {
- aFCA.lastSelection = text;
-
- if (aFCA.p.quick.menu || (aFCA.p.quick.bubble && (!doc.bubbleOk || !aFCA.translated || aFCA.isInBlacklist(doc.URL))))
- {
- var label_googleTranslate = aFCA.stringsBundle.getString("googleTranslate.label");
-
- aFCA.item1_quick.label = label_googleTranslate;
- aFCA.item1_quick.hidden = false;
- aFCA.sep_quick.hidden = false;
- aFCA.translateText(text, aFCA.p.quick.srcLang, aFCA.p.quick.destLang, aFCA.updateItem1);
- }
- else if (doc.preview)
- {
- aFCA.item1_quick.hidden = false;
- aFCA.sep_quick.hidden = false;
- }
-
- if (text.length > 15)
- {
- text = text.substr(0, 15) + "…";
- }
-
- if (aFCA.p.googleDictionary.bool)
- {
- var label_googleDictionary = aFCA.stringsBundle.getFormattedString("googleDictionary.label", [text]);
- var accesskey_googleDictionary = aFCA.stringsBundle.getString("googleDictionary.accesskey");
-
- aFCA.item_googleDictionary.hidden = false;
- aFCA.item_googleDictionary.label = label_googleDictionary;
- aFCA.item_googleDictionary.setAttribute("accesskey", accesskey_googleDictionary);
- }
-
- if (aFCA.p.customItem1.bool)
- {
- var label_customItem1 = aFCA.stringsBundle.getFormattedString("customItemX.label", [aFCA.p.customItem1.name, text]);
-
- aFCA.item_customItem1.hidden = false;
- aFCA.item_customItem1.label = label_customItem1;
- //aFCA.item_customItem1.setAttribute("accesskey", aFCA.p.customItem1.name[0]);
- }
-
- if (aFCA.p.customItem2.bool)
- {
- var label_customItem2 = aFCA.stringsBundle.getFormattedString("customItemX.label", [aFCA.p.customItem2.name, text]);
-
- aFCA.item_customItem2.hidden = false;
- aFCA.item_customItem2.label = label_customItem2;
- //aFCA.item_customItem2.setAttribute("accesskey", aFCA.p.customItem2.name[0]);
- }
-
- if (aFCA.p.customItem3.bool)
- {
- var label_customItem3 = aFCA.stringsBundle.getFormattedString("customItemX.label", [aFCA.p.customItem3.name, text]);
-
- aFCA.item_customItem3.hidden = false;
- aFCA.item_customItem3.label = label_customItem3;
- //aFCA.item_customItem3.setAttribute("accesskey", aFCA.p.customItem3.name[0]);
- }
-
- if ((aFCA.p.googleDictionary.bool || aFCA.p.customItem1.bool || aFCA.p.customItem2.bool || aFCA.p.customItem3.bool) && !(aFCA.item_copy.hidden && aFCA.item_selectall.hidden && aFCA.item_searchselect.hidden && aFCA.item_viewpartialsourceSelection.hidden))
- {
- aFCA.sep_searchItems.hidden = false;
- }
- }
-
- if (gContextMenu.onLink && !gContextMenu.onMailtoLink)
- {
- if (aFCA.p.stuff.newChildTab)
- {
- aFCA.item_newChildTab.hidden = false;
-
- if (!aFCA.p.pruning.openlink)
- {
- aFCA.sep_newChildTab.hidden = false;
- }
- }
- }
-
- if (!gContextMenu.onLink && !gContextMenu.isContentSelected && (!gContextMenu.isOnImage && aFCA.item_saveimage.hidden) && !gContextMenu.onTextInput)
- {
- var url = aFCA.getCurrentUrl();
-
- if (aFCA.p.stuff.bool && aFCA.ss.getTabValue(gBrowser.selectedTab, "ID"))
- {
- aFCA.item_restoreChildTab.hidden = false;
- aFCA.sep_restoreChildTab.hidden = false;
- }
-
- if (aFCA.p.stuff.bool && aFCA.ss.getTabValue(gBrowser.selectedTab, "parentTabID"))
- {
- aFCA.item_closeThisChildTab.hidden = false;
- aFCA.sep_closeThisChildTab.hidden = false;
- }
-
- if (aFCA.p.translateThisPage.bool && !url.match(/^https:\/\/|^http:\/\/translate\.google\.com|^http:\/\/www\.google\.com\/dictionary/))
- {
- aFCA.item_translateThisPage.hidden = false;
- aFCA.sep_translateThisPage.hidden = false;
- }
-
- if (aFCA.p.stuff.here || aFCA.p.quick.bubble || aFCA.p.stuff.middleClick)
- {
- if (aFCA.isInBlacklist(url))
- {
- var label_unblacklist = aFCA.stringsBundle.getFormattedString("unblacklist.label", [aFCA.urlToSite(url)]);
- var accesskey_unblacklist = aFCA.stringsBundle.getString("unblacklist.accesskey");
-
- aFCA.item_blacklist.hidden = false;
- aFCA.item_blacklist.label = label_unblacklist;
- aFCA.item_blacklist.setAttribute("accesskey", accesskey_unblacklist);
- aFCA.sep_blacklist.hidden = false;
- }
- else
- {
- var label_blacklist = aFCA.stringsBundle.getFormattedString("blacklist.label", [aFCA.urlToSite(url)]);
- var accesskey_blacklist = aFCA.stringsBundle.getString("blacklist.accesskey");
-
- aFCA.item_blacklist.hidden = false;
- aFCA.item_blacklist.label = label_blacklist;
- aFCA.item_blacklist.setAttribute("accesskey", accesskey_blacklist);
- aFCA.sep_blacklist.hidden = false;
- }
- }
- }
- },
-
-
- p:
- {
- googleDictionary: {},
- translateThisPage: {},
- customItem1: {},
- customItem2: {},
- customItem3: {},
- quick: {},
- stuff: {},
- pruning: {},
- bubble: {},
- quickW: {}
- },
-
-
- translateThisPage: function ()
- {
- if (aFCA.p.translateThisPage.inNewChildTab)
- {
- aFCA.openItem("translateThisPage");
- }
- else
- {
- var url = aFCA.getUrl("translateThisPage");
-
- loadURI(url);
- }
- },
-
-
- getPrefs: function ()
- {
- aFCA.p.locale = aFCA.prefsGeneral.getCharPref("useragent.locale");
-
- aFCA.p.autoConfig = aFCA.prefsAfca.getBoolPref("autoConfig");
-
- aFCA.p.blacklist = aFCA.prefsAfca.getCharPref("blacklist");
-
- aFCA.p.googleDictionary.bool = aFCA.prefsAfca.getBoolPref("googleDictionary.bool");
- aFCA.p.googleDictionary.langpair = aFCA.prefsAfca.getCharPref("googleDictionary.langpair");
- aFCA.p.googleDictionary.lang = aFCA.prefsAfca.getCharPref("googleDictionary.lang");
- aFCA.p.googleDictionary.bi = aFCA.prefsAfca.getBoolPref("googleDictionary.bi") && aFCA.p.googleDictionary.bool;
- aFCA.p.googleDictionary.mono = !aFCA.p.googleDictionary.bi && aFCA.p.googleDictionary.bool;
-
- aFCA.p.translateThisPage.bool = aFCA.prefsAfca.getBoolPref("translateThisPage.bool");
- aFCA.p.translateThisPage.destLang = aFCA.prefsAfca.getCharPref("translateThisPage.destLang");
- aFCA.p.translateThisPage.inNewChildTab = aFCA.prefsAfca.getBoolPref("translateThisPage.inNewChildTab");
-
- aFCA.p.customItem1.bool = aFCA.prefsAfca.getBoolPref("customItem1.bool");
- aFCA.p.customItem1.name = aFCA.prefsAfca.getCharPref("customItem1.name");
- aFCA.p.customItem1.url = aFCA.prefsAfca.getCharPref("customItem1.url");
-
- aFCA.p.customItem2.bool = aFCA.prefsAfca.getBoolPref("customItem2.bool");
- aFCA.p.customItem2.name = aFCA.prefsAfca.getCharPref("customItem2.name");
- aFCA.p.customItem2.url = aFCA.prefsAfca.getCharPref("customItem2.url");
-
- aFCA.p.customItem3.bool = aFCA.prefsAfca.getBoolPref("customItem3.bool");
- aFCA.p.customItem3.name = aFCA.prefsAfca.getCharPref("customItem3.name");
- aFCA.p.customItem3.url = aFCA.prefsAfca.getCharPref("customItem3.url");
-
- aFCA.p.quick.srcLang = aFCA.prefsAfca.getCharPref("quick.srcLang");
- aFCA.p.quick.destLang = aFCA.prefsAfca.getCharPref("quick.destLang");
- aFCA.p.quick.bool = aFCA.prefsAfca.getBoolPref("quick.bool");
- aFCA.p.quick.bMax = aFCA.prefsAfca.getIntPref("quick.bMax");
- aFCA.p.quick.mMax = aFCA.prefsAfca.getIntPref("quick.mMax");
- aFCA.p.quick.bubble = aFCA.prefsAfca.getBoolPref("quick.bubble") && aFCA.p.quick.bool;
- aFCA.p.quick.menu = !aFCA.p.quick.bubble && aFCA.p.quick.bool;
-
- aFCA.p.stuff.bool = aFCA.prefsAfca.getBoolPref("stuff.bool");
- aFCA.p.stuff.middleClick = aFCA.prefsAfca.getBoolPref("stuff.middleClick") && aFCA.p.stuff.bool;
- aFCA.p.stuff.dx = aFCA.prefsAfca.getIntPref("stuff.dx");
- aFCA.p.stuff.dy = aFCA.prefsAfca.getIntPref("stuff.dy");
- aFCA.p.stuff.newChildTab = aFCA.prefsAfca.getBoolPref("stuff.newChildTab") && aFCA.p.stuff.bool;
- aFCA.p.stuff.here = aFCA.prefsAfca.getBoolPref("stuff.here") && aFCA.p.stuff.bool;
- aFCA.p.stuff.unselect = aFCA.prefsAfca.getBoolPref("stuff.here.unselect");
-
- aFCA.p.pruning.openlink = aFCA.prefsAfca.getBoolPref("pruning.context-openlink");
- aFCA.p.pruning.bookmarklink = aFCA.prefsAfca.getBoolPref("pruning.context-bookmarklink");
- aFCA.p.pruning.sendlink = aFCA.prefsAfca.getBoolPref("pruning.context-sendlink");
- aFCA.p.pruning.sendimage = aFCA.prefsAfca.getBoolPref("pruning.context-sendimage");
- aFCA.p.pruning.setDesktopBackground = aFCA.prefsAfca.getBoolPref("pruning.context-setDesktopBackground");
- aFCA.p.pruning.blockimage = aFCA.prefsAfca.getBoolPref("pruning.context-blockimage");
- aFCA.p.pruning.sendvideo = aFCA.prefsAfca.getBoolPref("pruning.context-sendvideo");
- aFCA.p.pruning.sendaudio = aFCA.prefsAfca.getBoolPref("pruning.context-sendaudio");
- aFCA.p.pruning.back = aFCA.prefsAfca.getBoolPref("pruning.context-back");
- aFCA.p.pruning.forward = aFCA.prefsAfca.getBoolPref("pruning.context-forward");
- aFCA.p.pruning.reload = aFCA.prefsAfca.getBoolPref("pruning.context-reload");
- aFCA.p.pruning.stop = aFCA.prefsAfca.getBoolPref("pruning.context-stop");
- aFCA.p.pruning.bookmarkpage = aFCA.prefsAfca.getBoolPref("pruning.context-bookmarkpage");
- aFCA.p.pruning.savepage = aFCA.prefsAfca.getBoolPref("pruning.context-savepage");
- aFCA.p.pruning.sendpage = aFCA.prefsAfca.getBoolPref("pruning.context-sendpage");
- aFCA.p.pruning.viewbgimage = aFCA.prefsAfca.getBoolPref("pruning.context-viewbgimage");
- aFCA.p.pruning.undo = aFCA.prefsAfca.getBoolPref("pruning.context-undo");
- aFCA.p.pruning.cut = aFCA.prefsAfca.getBoolPref("pruning.context-cut");
- aFCA.p.pruning.copy = aFCA.prefsAfca.getBoolPref("pruning.context-copy");
- aFCA.p.pruning.paste = aFCA.prefsAfca.getBoolPref("pruning.context-paste");
- aFCA.p.pruning.del = aFCA.prefsAfca.getBoolPref("pruning.context-delete");
- aFCA.p.pruning.selectall = aFCA.prefsAfca.getBoolPref("pruning.context-selectall");
- aFCA.p.pruning.searchselect = aFCA.prefsAfca.getBoolPref("pruning.context-searchselect");
- aFCA.p.pruning.frame = aFCA.prefsAfca.getBoolPref("pruning.frame");
- aFCA.p.pruning.viewpartialsourceSelection = aFCA.prefsAfca.getBoolPref("pruning.context-viewpartialsource-selection");
- aFCA.p.pruning.viewsource = aFCA.prefsAfca.getBoolPref("pruning.context-viewsource");
- aFCA.p.pruning.spellCheck = aFCA.prefsAfca.getBoolPref("pruning.spell-check-enabled");
-
- aFCA.p.bubble.background = aFCA.prefsAfca.getCharPref("bubble.background");
- aFCA.p.bubble.fontSize = aFCA.prefsAfca.getCharPref("bubble.fontSize");
- aFCA.p.bubble.fontWeight = aFCA.prefsAfca.getCharPref("bubble.fontWeight");
- aFCA.p.bubble.fontFamily = aFCA.prefsAfca.getCharPref("bubble.fontFamily");
- aFCA.p.bubble.fontColor = aFCA.prefsAfca.getCharPref("bubble.fontColor");
-
- aFCA.p.quickW.srcLang = aFCA.prefsAfca.getCharPref("quickW.srcLang");
- aFCA.p.quickW.destLang = aFCA.prefsAfca.getCharPref("quickW.destLang");
- },
-
-
- observe: function (subject, topic, data)
- {
- if (topic != "nsPref:changed")
- {
- return;
- }
-
- aFCA.getPrefs();
-
- var doc = content.document;
-
- switch (data)
- {
- case "quick.bool":
- {
- aFCA.hideBubble();
-
- if (aFCA.p.quick.bubble)
- {
- aFCA.initBubble(doc);
- }
- break;
- }
- case "quick.bubble":
- {
- aFCA.hideBubble();
-
- if (aFCA.p.quick.bubble)
- {
- aFCA.initBubble(doc);
- }
- break;
- }
- case "stuff.here":
- {
- aFCA.hideHere();
-
- if (aFCA.p.stuff.here)
- {
- aFCA.initHere(doc);
- }
- break;
- }
- case "stuff.bool":
- {
- aFCA.hideHere();
- aFCA.hideSkin();
-
- if (aFCA.p.stuff.here)
- {
- aFCA.initHere(doc);
- }
-
- if (!aFCA.p.stuff.middleClick)
- {
- aFCA.prefsGeneral.setBoolPref("autoScroll", true);
- }
- else
- {
- aFCA.prefsGeneral.setBoolPref("autoScroll", false);
- }
-
- break;
- }
- case "stuff.middleClick":
- {
- aFCA.hideSkin();
-
- if (aFCA.ss.getTabValue(gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(doc)], "parentTabID") && aFCA.p.stuff.middleClick)
- {
- aFCA.initSkin(doc);
- }
-
- if (!aFCA.p.stuff.middleClick)
- {
- aFCA.prefsGeneral.setBoolPref("autoScroll", true);
- }
- else
- {
- aFCA.prefsGeneral.setBoolPref("autoScroll", false);
- }
-
- break;
- }
- case "blacklist":
- {
- aFCA.hideBubble();
- aFCA.hideSkin();
- aFCA.hideHere();
-
- if (aFCA.p.quick.bubble)
- {
- aFCA.initBubble(doc);
- }
- if (aFCA.ss.getTabValue(gBrowser.mTabs[gBrowser.getBrowserIndexForDocument(doc)], "parentTabID") && aFCA.p.stuff.middleClick)
- {
- aFCA.initSkin(doc);
- }
- if (aFCA.p.stuff.here)
- {
- aFCA.initHere(doc);
- }
- break;
- }
- }
- },
-
-
- blacklist: function ()
- {
- var url = aFCA.getCurrentUrl();
- var site = aFCA.urlToSite(url);
- var blacklist = aFCA.p.blacklist;
-
- if (blacklist.match(site))
- {
- blacklist = blacklist.replace(site + ", ", "");
- aFCA.prefsAfca.setCharPref("blacklist", blacklist);
- }
- else
- {
- blacklist = blacklist.replace(/,\s$/, ", " + site + ", ");
- aFCA.prefsAfca.setCharPref("blacklist", blacklist);
- }
- },
-
-
- isInBlacklist: function (url)
- {
- var site = aFCA.urlToSite(url);
- return aFCA.p.blacklist.match(site);
- },
-
-
- urlToSite: function (url)
- {
- return url.replace(/^.+:\/\//, "").replace(/\/.+/, "").replace("/", "");
- },
-
-
- skinProp:
- {
- w: 11,
- h: 11,
- path: "chrome://aFewClicksAway/skin/skin11.png"
- },
-
-
- initSkin: function (doc)
- {
- if (doc.skinOk || aFCA.isInBlacklist(doc.URL) || !doc.body)
- {
- return;
- }
- doc.skinOk = true;
-
- aFCA.injectStretch(doc);
- aFCA.injectSkin(doc);
- aFCA.addSkinEvents(doc);
- },
-
-
- addSkinEvents: function (doc)
- {
- doc.addEventListener("mousemove", function (e) {aFCA.lastMouseMove = e; aFCA.updateSkinDisplay(e);}, false);
-
- aFCA.addOnMouseDown(doc);
-
- function onMouseOut (e)
- {
- var p = aFCA.getMousePositionOnClient(e);
-
- if (p.x < 0 || p.y < 0)
- {
- aFCA.hideSkin();
- }
- }
- doc.addEventListener("mouseout", function (e) {onMouseOut(e);}, true);
- //Obviously stopping event propagation in the capturing phase is impossible...
-
- var anchors = doc.getElementsByTagName("a");
-
- for (var x = 0; x < anchors.length; x++)
- {
- anchors[x].addEventListener("mouseover", function () {doc.skinHiddenBecauseAnchor = true;}, false);
- anchors[x].addEventListener("mouseout", function () {doc.skinHiddenBecauseAnchor = false;}, false);
- }
- },
-
-
- injectSkin: function (doc)
- {
- if (doc.getElementById("skin"))
- {
- return;
- }
-
- var p = aFCA.skinProp;
- var skin = doc.createElement("div");
-
- skin.id = "skin";
-
- skin.style.position = "fixed";
- skin.style.display = "none";
- skin.style.left = "0px";
- skin.style.top = "0px";
- skin.style.width = p.w + "px";
- skin.style.height = p.h + "px";
- skin.style.background = "url(" + p.path + ")";
- skin.style.zIndex= "10000";
-
- doc.body.appendChild(skin);
- },
-
-
- hideSkin: function ()
- {
- var skin = content.document.getElementById("skin");
-
- if (skin)
- {
- skin.style.display = "none";
- }
- },
-
-
- updateSkinDisplay: function (e)
- {
- var doc = content.document;
- var m = aFCA.getMousePositionOnClient(e);
- var skin = doc.getElementById("skin");
-
- if (!skin)
- {
- return;
- }
-
- if (!doc.skinHiddenBecauseAnchor && !aFCA.isInBlacklist(doc.URL) && !gContextMenu && aFCA.p.stuff.middleClick)
- {
- skin.style.left = m.x + aFCA.p.stuff.dx + "px";
- skin.style.top = m.y + aFCA.p.stuff.dy + "px";
-
- skin.style.display = "block";
- }
- else
- {
- skin.style.display = "none";
- }
- },
-
-
- translateText: function (text, srcLang, destLang, callback)
- {
- if (text.length > 5000)
- {
- text = text.substr(0, 5000);
- }
-
- if (srcLang == "auto")
- {
- srcLang = "";
- }
-
- text = encodeURIComponent(text);
-
- var url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + text + "&langpair=" + srcLang + "%7C" + destLang;
- var referer = "http://addons.mozilla.org/addon/13547";
-
- function handler ()
- {
- if (req.readyState == 4)
- {
- var json = JSON.parse(req.responseText);
-
- if (!json)
- {
- return callback("Oops…");
- }
-
- var translatedText = json.responseData.translatedText;
- aFCA.lastTranslation = translatedText;
-
- if (!srcLang)
- {
- var detectedLanguage = json.responseData.detectedSourceLanguage;
- }
- else
- {
- var detectedLanguage = "";
- }
-
- return callback(translatedText, detectedLanguage);
- }
- }
-
- var req = new XMLHttpRequest();
-
- req.onreadystatechange = handler;
- req.open("GET", url);
- req.setRequestHeader("Referer", referer);
- req.send();
- },
-
-
- detectLanguage: function (text, callback)
- {
- if (text.length > 100)
- {
- text = text.substr(0, 100);
- }
-
- text = encodeURIComponent(text);
-
- var url = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=" + text;
- var referer = "http://addons.mozilla.org/addon/13547";
-
- function handler ()
- {
- if (req.readyState == 4)
- {
- var json = JSON.parse(req.responseText);
-
- if (!json)
- {
- return callback("Oops…");
- }
-
- var language = json.responseData.language;
-
- return callback(language);
- }
- }
-
- var req = new XMLHttpRequest();
-
- req.onreadystatechange = handler;
- req.open("GET", url);
- req.setRequestHeader("Referer", referer);
- req.send();
- },
-
-
- isTranslatable: function (text)
- {
- return (text && !((!text.match(" ") && text.match(/\w\.\w|\d/))) && !text.match(/@|#|{|}|<|>|_|\+/));
- },
-
-
- displayBubble: function (translation, detectedLanguage)
- {
- aFCA.translated = true;
-
- var destLang = aFCA.p.quick.destLang;
- var doc = content.document;
- var bubble = doc.getElementById("bubble-div");
- var n = aFCA.p.quick.bMax;
-
- if (detectedLanguage == destLang || !aFCA.getSelectedText() || aFCA.isInBlacklist(doc.URL) || !bubble)
- {
- return;
- }
-
- if (translation.length > n)
- {
- doc.preview = true;
- aFCA.updateItem1(translation);
- translation = translation.substr(0, n) + "…";
- }
-
- var ed = aFCA.lastMouseDown;
- var eu = aFCA.lastMouseUp;
- var ppd = aFCA.getMousePositionOnPage(ed);
- var pcd = aFCA.getMousePositionOnClient(ed);
- var ppu = aFCA.getMousePositionOnPage(eu);
- var pcu = aFCA.getMousePositionOnClient(eu);
-
- if (ppd.x - ppu.x < 0)
- {
- var ppx = ppd;
- var pcx = pcd;
- }
- else
- {
- var ppx = ppu;
- var pcx = pcu;
- }
-
- if (ppd.y - ppu.y < 0)
- {
- var ppy = ppd;
- var pcy = pcd;
- }
- else
- {
- var ppy = ppu;
- var pcy = pcu;
- }
-
- var fontSize = parseInt(bubble.style.fontSize);
- var height = 32 + fontSize;
-
- if (pcy.y - height < 0)
- {
- bubble.style.top = ppy.y + 17 + "px";
- }
- else
- {
- bubble.style.top = ppy.y - height + "px";
- }
-
- if (ppd.y == ppu.y && ppd.x == ppu.x)
- {
- bubble.style.left = ppx.x - 20 + "px";
- }
- else
- {
- bubble.style.left = ppx.x - 10 + "px";
- }
-
- bubble.innerHTML = translation;
- bubble.style.display = "block";
-
- var divHeight = bubble.offsetHeight;
- var lineHeight = bubble.style.lineHeight * parseInt(bubble.style.fontSize);
- var padding = parseInt(bubble.style.padding);
-
- var lines = Math.floor((divHeight - 2*padding) / lineHeight);
-
- if (lines != 1)
- {
- bubble.style.left = "10px";
-
- var w = doc.getElementsByTagName("html")[0].clientWidth;
- var divWidth = bubble.offsetWidth;
-
- bubble.style.left = w - divWidth -10 + "px";
- }
- },
-
-
- updateItem1: function (translation, detectedLanguage)
- {
- translation = aFCA.processText(translation);
-
- var n = aFCA.p.quick.mMax;
-
- if (translation.length > n)
- {
- translation = translation.substr(0, n) + "…";
- }
-
- aFCA.item1_quick.label = translation;
- },
-
-
- updateItem2: function (translation, detectedLanguage)
- {
- translation = aFCA.processText(translation);
-
- var n = aFCA.p.quick.mMax;
-
- if (translation.length > n)
- {
- translation = translation.substr(0, n) + "…";
- }
-
- aFCA.item2_quick.label = translation;
- },
-
-
- processText: function (text)
- {
- return text.replace(/'/g, "'")
- .replace(/"/g, '"')
- .replace(/\.\.\./g, "…");
- },
-
-
- addOnMouseDown: function (doc)
- {
- if (doc.onMouseDownAdded || !doc.body)
- {
- return;
- }
- doc.onMouseDownAdded = true;
-
- function onMouseDown (e)
- {
- if (e.button == 0)
- {
- aFCA.textOnMouseDown = aFCA.getSelectedText();
- aFCA.lastMouseDown = e;
-
- aFCA.hideHere();
-
- if (!doc.holdOn)
- {
- aFCA.hideBubble();
- }
-
- doc.preview = false;
- }
-
- if (e.button == 2)
- {
- aFCA.lastRightClick = e;
- }
-
- var skin = doc.getElementById("skin");
-
- if (e.button == 0 || e.button == 1)
- {
- if (skin)
- {
- aFCA.updateSkinDisplay(e);
- }
- }
-
- if (e.button == 1 && skin && skin.style.display == "block")
- {
- aFCA.closeAndGo("click");
- }
- }
- doc.addEventListener("mousedown", function (e) {onMouseDown(e);}, false);
- },
-
-
- addOnMouseUp: function (doc)
- {
- if (doc.onMouseUpAdded || !doc.body)
- {
- return;
- }
- doc.onMouseUpAdded = true;
-
- function onMouseUp (e)
- {
- if (e.button == 0)
- {
- aFCA.lastMouseUp = e;
-
- var ed = aFCA.lastMouseDown;
- var eu = aFCA.lastMouseUp;
- var ppd = aFCA.getMousePositionOnPage(ed);
- var ppu = aFCA.getMousePositionOnPage(eu);
-
- if (ppd.y == ppu.y && ppd.x == ppu.x && aFCA.textOnMouseDown)
- {
- return;
- }
-
- var text = aFCA.getSelectedText();
-
- if (aFCA.p.quick.bubble && aFCA.isTranslatable(text) && !doc.holdOn)
- {
- aFCA.hideBubble();
- aFCA.translated = false;
- aFCA.translateText(text, aFCA.p.quick.srcLang, aFCA.p.quick.destLang, aFCA.displayBubble);
- }
-
- if (text && !doc.holdOn)
- {
- aFCA.lastSelectionEvent = aFCA.lastMouseDown;
- }
- }
- }
- doc.addEventListener("mouseup", function (e) {onMouseUp(e);}, false);
- },
-
-
- hideBubble: function ()
- {
- var bubble = content.document.getElementById("bubble-div");
-
- if (bubble)
- {
- bubble.style.display = "none";
- }
- },
-
-
- initBubble: function (doc)
- {
- if (doc.bubbleOk || aFCA.isInBlacklist(doc.URL) || !doc.body)
- {
- return;
- }
- doc.bubbleOk = true;
-
- aFCA.injectStretch(doc);
- aFCA.injectBubble(doc);
- aFCA.addOnMouseDown(doc);
- aFCA.addOnMouseUp(doc);
- },
-
-
- injectBubble: function (doc)
- {
- if (doc.getElementById("bubble-div"))
- {
- return;
- }
-
- var bubble = doc.createElement("div");
-
- bubble.id = "bubble-div";
-
- bubble.style.position = "absolute";
- bubble.style.display = "none";
- bubble.style.left = "0px";
- bubble.style.top = "0px";
- bubble.style.zIndex = "10000";
- bubble.style.width = "auto";
- bubble.style.heigth = "auto";
- bubble.style.padding = "6px";
- bubble.style.border = "thin solid grey";
- bubble.style.background = aFCA.p.bubble.background;
- bubble.style.color = aFCA.p.bubble.fontColor;
- bubble.style.marginRight = "9px";
- bubble.style.lineHeight = "1";
- bubble.style.fontSize = aFCA.p.bubble.fontSize;
- bubble.style.fontWeight = aFCA.p.bubble.fontWeight;
- bubble.style.fontFamily = aFCA.p.bubble.fontFamily;
-
- doc.body.appendChild(bubble);
-
- aFCA.injectStyle(doc, "div#bubble-div{-moz-border-radius: 5px; -moz-box-shadow: black 3px 3px 6px;}", "bubble-style");
-
- bubble.addEventListener("mouseover", function () {doc.holdOn = true;}, false);
- bubble.addEventListener("mouseout", function () {doc.holdOn = false;}, false);
- },
-
-
- getMousePositionOnPage: function (e)
- {
- var position =
- {
- x: e.pageX,
- y: e.pageY
- }
- return position;
- },
-
-
- getMousePositionOnClient: function (e)
- {
- var position =
- {
- x: e.clientX,
- y: e.clientY
- }
- return position;
- },
-
-
- injectStyle: function (doc, css, id)
- {
- if (doc.getElementById(id) || !doc.body)
- {
- return;
- }
-
- var style = doc.createElement("style");
- style.type = "text/css";
- style.innerHTML = css;
- style.id = id;
- doc.body.appendChild(style);
- },
-
-
- initHere: function (doc)
- {
- if (doc.hereOk || aFCA.isInBlacklist(doc.URL) || !doc.body)
- {
- return;
- }
- doc.hereOk = true;
-
- aFCA.injectStretch(doc);
- aFCA.injectHere(doc);
- aFCA.addOnMouseDown(doc);
- aFCA.addOnMouseUp(doc);
- },
-
-
- hereProp:
- {
- w: 50,
- h: 32,
- path: "chrome://aFewClicksAway/skin/red-dot-shadow.png"
- },
-
-
- injectHere: function (doc)
- {
- if (doc.getElementById("here"))
- {
- return;
- }
-
- var p = aFCA.hereProp;
- var here = doc.createElement("div");
-
- here.id = "here";
-
- here.style.position = "absolute";
- here.style.display = "none";
- here.style.left = "0px";
- here.style.top = "0px";
- here.style.width = p.w + "px";
- here.style.height = p.h + "px";
- here.style.background = "url(" + p.path + ")";
- here.style.zIndex= "10000";
-
- doc.body.appendChild(here);
- },
-
-
- updateHereDisplay: function (e)
- {
- var doc = content.document;
- var here = doc.getElementById("here");
-
- if (!here || aFCA.isInBlacklist(doc.URL))
- {
- return;
- }
-
- var m = aFCA.getMousePositionOnPage(e);
- var p = aFCA.hereProp;
-
- here.style.left = m.x - p.w/2 + "px";
- here.style.top = m.y - p.h + "px";
- here.style.display = "block";
- },
-
-
- hideHere: function ()
- {
- var here = content.document.getElementById("here");
-
- if (here)
- {
- here.style.display = "none";
- }
- },
-
-
- codeToLanguage: function (code)
- {
- return aFCA.stringsBundle.getString("lang." + code);
- }
- }
-
- window.addEventListener("load", function () {aFCA.init();}, false);